package org.bddall.stepdefs;

import io.cucumber.java.zh_cn.假如;
import io.cucumber.java.zh_cn.当;
import io.cucumber.java.zh_cn.那么;
import org.bddall.page.LoginPage;
import org.bddall.util.WebDriverFactory;
import org.junit.Assert;
import org.openqa.selenium.WebDriver;

public class LoginStepdefs {
    private WebDriver driver;
    private LoginPage loginPage;
    public LoginStepdefs(){
        this.driver = WebDriverFactory.driver();
        loginPage = new LoginPage(driver);
    }
    @假如("用户进入后台登录页面$")
    public void 用户进入后台登录页面() {
        // Write code here that turns the phrase above into concrete actions
        driver.get("http://demoadmin.moguit.cn/");
    }
    @当("用户需要输入用户名([^\\\"]*)和密码([^\\\"]*)然后点击登录$")
    public void 用户需要输入用户名_和密码_然后点击登录(String userName,String password) {
        // Write code here that turns the phrase above into concrete actions
        //从Feature文件获取用户名并在浏览器中输入用户名
        loginPage.setUserName(userName);
        //从Feature文件获取密码并再浏览器中输入密码
        loginPage.setPassword(password);
        //点击登录按钮登录平台
        loginPage.login();

    }
    @那么("用户登录平台并显示首页$")
    public void 用户登录平台并显示首页() {
        // Write code here that turns the phrase above into concrete actions
        Assert.assertTrue(loginPage.isLoninSuccessful());
        driver.quit();
    }
}
